<h1 id="pv">pv</h1>
<p>显示当前在命令行执行的命令的进度信息，管道查看器。</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>pv命令</strong> Pipe Viewer 的简称，由Andrew Wood 开发。意思是通过管道显示数据处理进度的信息。这些信息包括已经耗费的时间，完成的百分比(通过进度条显示)，当前的速度，全部传输的数据，以及估计剩余的时间。</p>
<h2 id="下载安装">下载安装</h2>
<div class="sourceCode" id="cb1"><pre><code class="language-bash"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="co"># Debian 系的操作系统，如 Ubuntu</span></a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="fu">sudo</span> apt-get install pv</a>
<a class="sourceLine" id="cb1-3" data-line-number="3"></a>
<a class="sourceLine" id="cb1-4" data-line-number="4"><span class="co"># RedHat系的则这样：</span></a>
<a class="sourceLine" id="cb1-5" data-line-number="5"><span class="ex">yum</span> install pv</a></code></pre></div>
<h3 id="语法">语法</h3>
<div class="sourceCode" id="cb2"><pre><code class="language-bash"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="ex">pv</span>(选项)<span class="kw">(</span>参数<span class="kw">)</span></a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="ex">pv</span> [OPTION] [FILE]...</a></code></pre></div>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-p, --progress           show progress bar
-t, --timer              show elapsed time
-e, --eta                show estimated time of arrival (completion)
-I, --fineta             show absolute estimated time of arrival
                         (completion)
-r, --rate               show data transfer rate counter
-a, --average-rate       show data transfer average rate counter
-b, --bytes              show number of bytes transferred
-T, --buffer-percent     show percentage of transfer buffer in use
-A, --last-written NUM   show NUM bytes last written
-F, --format FORMAT      set output format to FORMAT
-n, --numeric            输出百分比
-q, --quiet              do not output any transfer information at all

-W, --wait               display nothing until first byte transferred
-D, --delay-start SEC    display nothing until SEC seconds have passed
-s, --size SIZE          set estimated data size to SIZE bytes
-l, --line-mode          count lines instead of bytes
-0, --null               lines are null-terminated
-i, --interval SEC       update every SEC seconds
-w, --width WIDTH        assume terminal is WIDTH characters wide
-H, --height HEIGHT      assume terminal is HEIGHT rows high
-N, --name NAME          prefix visual information with NAME
-f, --force              output even if standard error is not a terminal
-c, --cursor             use cursor positioning escape sequences

-L, --rate-limit RATE    limit transfer to RATE bytes per second
-B, --buffer-size BYTES  use a buffer size of BYTES
-C, --no-splice          never use splice(), always use read/write
-E, --skip-errors        skip read errors in input
-S, --stop-at-size       stop after --size bytes have been transferred
-R, --remote PID         update settings of process PID

-P, --pidfile FILE       save process ID in FILE

-d, --watchfd PID[:FD]   watch file FD opened by process PID

-h, --help               显示帮助
-V, --version            显示版本信息</code></pre>
<h3 id="实例">实例</h3>
<p>我们（在 linux 上使用命令行的用户）的大多数使用场景都会用到的命令是从一个 USB 驱动器拷贝电影文件到你的电脑。如果你使用 cp 来完成上面的任务，你会什么情况都不清楚，直到整个复制过程结束或者出错。</p>
<div class="sourceCode" id="cb4"><pre><code class="language-bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="co"># 复制文件会有进度</span></a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="ex">linux</span> [master●] % pv ~/Downloads/CentOS-7-x86_64-Minimal-1511.iso <span class="op">&gt;</span> ~/Desktop/CentOS-7-x86_64-Minimal-1511.iso</a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="co"># 下面输入信息</span></a>
<a class="sourceLine" id="cb4-4" data-line-number="4"><span class="ex">552MiB</span> 0:00:02 [ 212MiB/s] [==================<span class="op">&gt;</span>           ] 91% ETA 0:00:00</a>
<a class="sourceLine" id="cb4-5" data-line-number="5"></a>
<a class="sourceLine" id="cb4-6" data-line-number="6"><span class="co"># -L 可以让你修改 pv 命令的传输速率。</span></a>
<a class="sourceLine" id="cb4-7" data-line-number="7"><span class="co"># 使用 -L 选项来限制传输速率为2MB/s。</span></a>
<a class="sourceLine" id="cb4-8" data-line-number="8"><span class="ex">pv</span> -L 2m /media/himanshu/1AC2-A8E3/fNf.mkv <span class="op">&gt;</span> ./Desktop/fnf.mkv </a></code></pre></div>
<div class="sourceCode" id="cb5"><pre><code class="language-bash"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="co"># 字符一个个匀速在命令行中显示出来</span></a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="bu">echo</span> <span class="st">&quot;Tecmint[dot]com is a community of Linux Nerds and Geeks&quot;</span> <span class="kw">|</span> <span class="ex">pv</span> -qL 10</a>
<a class="sourceLine" id="cb5-3" data-line-number="3"></a>
<a class="sourceLine" id="cb5-4" data-line-number="4"><span class="co"># 压缩文件展示进度信息</span></a>
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="ex">pv</span> /media/himanshu/1AC2-A8E3/fnf.mkv <span class="kw">|</span> <span class="fu">gzip</span> <span class="op">&gt;</span> ./Desktop/fnf.log.gz </a>
<a class="sourceLine" id="cb5-6" data-line-number="6"></a>
<a class="sourceLine" id="cb5-7" data-line-number="7"></a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="co"># 用 dd 命令将 iso 写入磁盘，pv来实现进度条的显示</span></a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="fu">sudo</span> pv -cN source <span class="op">&lt;</span> /Users/kacperwang/Downloads/CentOS-7-x86_64-Everything-1511.iso <span class="kw">|</span> <span class="fu">sudo</span> dd of=/dev/disk2 bs=4m</a>
<a class="sourceLine" id="cb5-10" data-line-number="10"><span class="co">## 显示下面进度</span></a>
<a class="sourceLine" id="cb5-11" data-line-number="11"><span class="ex">source</span>:  5.2GiB 5:11:41 [ 503KiB/s] [=====================<span class="op">&gt;</span>       ] 71% ETA 2:01:56</a></code></pre></div>
<!-- Linux命令行搜索引擎：https://jaywcjlove.github.io/linux-command/ -->
